package com.sunwayworld.common.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class SessionUtils {

	public static String LOGIN_USERID = "LOGIN_USERID";

	public static String LOGIN_USER = "LOGIN_USER";

	public static String getSessionid(HttpServletRequest request) {
		HttpSession session = request.getSession();
		return session.getId();
	}

	public static boolean isLogin(HttpServletRequest request) {
		Object obj = getUserInfo(request);
		return null != obj;

	}

	public static String getUserId(HttpServletRequest request) {
		HttpSession session = request.getSession();
		String userId = StringUtils
				.toString(session.getAttribute(LOGIN_USERID));
		return userId;
	}

	public static Object getUserInfo(HttpServletRequest request) {
		HttpSession session = request.getSession();
		return session.getAttribute(LOGIN_USER);

	}

	public static void setUserInfo(HttpServletRequest request, Object obj) {
		HttpSession session = request.getSession();
		session.setAttribute(LOGIN_USER, obj);
	}
}
